package cn.tqfeiyang.smartadmin.commons.toolbox;

import java.util.Objects;

/**
 * 数字工具类
 *
 * @author tqfeiyang
 * @since 2024/10/9 11:22
 */
public class NumberUtils {

    private NumberUtils() {}

    /**
     * 检查数值是否不为0
     *
     * @param num
     * @return 如果不为0则返回true，否则返回false
     */
    public static boolean nonZero(Number num) {
        if (Objects.nonNull(num)) {
            if (num instanceof Byte && num.byteValue() != 0) {
                return true;
            } else if (num instanceof Short && num.shortValue() != 0) {
                return true;
            } else if (num instanceof Integer && num.intValue() != 0) {
                return true;
            } else if (num instanceof Long && num.longValue() != 0) {
                return true;
            } else if (num instanceof Float && num.floatValue() != 0) {
                return true;
            } else if (num instanceof Double && num.doubleValue() != 0) {
                return true;
            }
        }
        return false;
    }
}
